package com.jkoss.wine.shop.controller;

import javax.validation.Valid;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jkoss.base.controller.BaseController;
import com.jkoss.common.vo.DwzPageBean;
import com.jkoss.wine.customer.entity.Shop;
import com.jkoss.wine.investment.entity.Handover;
import com.jkoss.wine.investment.service.IHandoverService;

/**
 * 新客户基本情况交接表 前端控制器
 * 
 * @Author garden
 * @Version 1.0, 2019-08-22
 * @See
 * @Since com.ossjk.oa.handover.controller
 * @Description: TODO
 */
@Controller
@RequestMapping("/shop/handover")
public class ShopHandoverController extends BaseController {

	@Autowired
	private IHandoverService iHandoverService;

	@RequestMapping("/list")
	@RequiresPermissions("/shop/handover/list")
	public String list(DwzPageBean dwzPageBean, ModelMap map) {
		// 列表内容
		Wrapper wrapper = Condition.create().eq("del", 0);
		Page resultPage = iHandoverService.selectPage(dwzPageBean.toPage(), wrapper);
		map.put("dwzPageBean", dwzPageBean.toDwzPageBean(resultPage));
		return "/shop/handover/list";
	}

	@RequestMapping("/toReview")
	@RequiresPermissions("/shop/handover/toReview")
	public String toReview(String id, DwzPageBean dwzPageBean, ModelMap map) {
		map.put("record", iHandoverService.selectById(id));
		return "shop/handover/edit";
	}

	@RequestMapping("/turnOver")
	@RequiresPermissions("/shop/handover/turnOver")
	@ResponseBody
	public Object turnOver(@Valid Shop shop, Handover handover, DwzPageBean dwzPageBean, ModelMap map) {
		handover.setState(2);
		// map.put("record", iHandoverService.selectById(id));
		
		
		if (iHandoverService.updateById(handover)) {
			return ajaxSuccess();
		} else {
			return ajaxError();
		}
	}

	@RequestMapping("/turnOverFail")
	@RequiresPermissions("/shop/handover/turnOverFail")
	@ResponseBody
	public Object turnOverFail(Handover handover, DwzPageBean dwzPageBean, ModelMap map) {
		handover.setState(3);
		if (iHandoverService.updateById(handover)) {
			return ajaxSuccess();
		} else {
			return ajaxError();
		}
	}
}
